package com.han.practice;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;

public class Solution {
    public static void main(String[] args) throws IOException {

/*        System.out.println("Test for No5");
        No5 no5 = new No5();
        System.out.println(no5.longestPalindrome("ac"));

         超时
        System.out.println(no5.longestPalindrome("ibvjkmpyzsifuxcabqqpahjdeuzaybqsrsmbfplxycsafogotliyvhxjtkrbzqxlyfwujzhkdafhebvsdhkkdbhlhmaoxmbkqiwiusngkbdhlvxdyvnjrzvxmukvdfobzlmvnbnilnsyrgoygfdzjlymhprcpxsnxpcafctikxxybcusgjwmfklkffehbvlhvxfiddznwumxosomfbgxoruoqrhezgsgidgcfzbtdftjxeahriirqgxbhicoxavquhbkaomrroghdnfkknyigsluqebaqrtcwgmlnvmxoagisdmsokeznjsnwpxygjjptvyjjkbmkxvlivinmpnpxgmmorkasebngirckqcawgevljplkkgextudqaodwqmfljljhrujoerycoojwwgtklypicgkyaboqjfivbeqdlonxeidgxsyzugkntoevwfuxovazcyayvwbcqswzhytlmtmrtwpikgacnpkbwgfmpavzyjoxughwhvlsxsgttbcyrlkaarngeoaldsdtjncivhcfsaohmdhgbwkuemcembmlwbwquxfaiukoqvzmgoeppieztdacvwngbkcxknbytvztodbfnjhbtwpjlzuajnlzfmmujhcggpdcwdquutdiubgcvnxvgspmfumeqrofewynizvynavjzkbpkuxxvkjujectdyfwygnfsukvzflcuxxzvxzravzznpxttduajhbsyiywpqunnarabcroljwcbdydagachbobkcvudkoddldaucwruobfylfhyvjuynjrosxczgjwudpxaqwnboxgxybnngxxhibesiaxkicinikzzmonftqkcudlzfzutplbycejmkpxcygsafzkgudy"));

        System.out.println(no5.longestPalindrome2("ibvjkmpyzsifuxcabqqpahjdeuzaybqsrsmbfplxycsafogotliyvhxjtkrbzqxl" +
                "yfwujzhkdafhebvsdhkkdbhlhmaoxmbkqiwiusngkbdhlvxdyvnjrzvxmukvdfobzlmvnbnilnsyrgoygfdzjlymhprcpxsnxpcaf" +
                "ctikxxybcusgjwmfklkffehbvlhvxfiddznw"));*/

        // 测试正则表达式
/*        No10 no10 = new No10();
        String s = "abcd";
        String p = ".*";
        System.out.println(no10.isMatch(s, p));*/

/*        final int MAX = 998244353;

        Scanner in = new Scanner(System.in);
        int len = in.nextInt();
        int[] an = new int[len];
        for(int i=0; i<len; i++) an[i] = in.nextInt();

        // 先对数组进行排序
        Arrays.sort(an);
        int sum = 0;
        for(int i=0; i<len; i++){
            sum = 0;
            for(int j=i; j<len; j++){
                sum = sum + an[j] * caculate(j-1, j-i);
                sum %= MAX;
            }
            System.out.print(sum);
            System.out.print(" ");*/

/*        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int T=Integer.parseInt(br.readLine().trim());
        while(T-->0){
            int n=Integer.parseInt(br.readLine().trim());
            int[] d=new int[n];
            // String[] parts=br.readLine().split(" ");
            StringTokenizer st=new StringTokenizer(br.readLine().trim());
            for(int i=0;i<n;i++){
                d[i]=Integer.parseInt(st.nextToken());
            }
            int count =0;
            int right=n;
            int i=n-1;
            while(i>=0){
                if(i<right){
                    count++;
                    right=Math.min(right,i-d[i]);
                    if(right<=0){break;}
                }
                i--;
            }
            System.out.println(count);
        }*/

/*        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(br.readLine());
        char[] s=br.readLine().toCharArray();
        char[] res=s.clone();
        for(int i=0;i<n;i++){
            int bestLeft=-1;
            for(int k=1;i-k>=0;k++){
                if(s[i-k]<s[i]){
                    bestLeft=i-k;
                    break;
                }
            }

            if(bestLeft!=-1){
                char[] temp=s.clone();
                char t=temp[i];
                temp[i]=temp[bestLeft];
                temp[bestLeft]=t;
                if(new String(temp).compareTo(new String(res))<0){
                    res=temp.clone();
                }
            }

            for(int j=i+1;j<n;j++){
                for(int k=1;j+k<n;k++){
                    if(s[j+k]<s[j]){
                        char[] temp=s.clone();
                        char t=temp[i];
                        temp[j]=temp[j+k];
                        temp[j+k]=t;

                        if(new String(temp).compareTo(new String(res))<0){
                            res=temp.clone();
                        }
                        break;
                    }
                }
            }
        }
        System.out.println(new String(res));*/

/*        Scanner sc = new Scanner(System.in);
        String[] ss = sc.nextLine().split(" ");
        int k = sc.nextInt();
        int len = ss.length;
        k %= len;

        int countOuter = gcd(len, k);
        int countInner = len/countOuter;

//        int nowP = 0;
        int nextP = k;
        String tmp = ss[0];

        for(int i=0; i< countOuter; i++){
            for(int j=0; j<countInner; j++){
                String newTmp = ss[nextP];
                ss[nextP] = tmp;
                tmp = newTmp;
//                nowP = nextP;
                nextP = (nextP + k) % len;
            }
        }
        for(String s : ss){
            System.out.print(s+" ");
        }*/

/*        Scanner sc = new Scanner(System.in);
        char[] cs = sc.nextLine().toCharArray();
        if(cs.length < 1) {
            System.out.println(0);
            return;
        }
        int maxLen = 0;
        int len = 0;
        int leftC = 0;

        for(int i=0; i<cs.length; i++){
            if(cs[i] == '('){
                leftC++;
                len++;
            }else{
                if(leftC > 0){
                    leftC--;
                    len++;
                }else{
                    maxLen = (len > maxLen? len : maxLen);
                }
            }
        }
        System.out.println(maxLen);*/


/*        Scanner sc = new Scanner(System.in);
        String eq = sc.nextLine(); // equation

        // get x
        char x = ' ';
        for(int i=0; i<eq.length(); i++){
            x = eq.charAt(i);
            if(x>='a' && x<='z') break;
        }

        // split to left & right
        String[] eqs = eq.split("=");

        // caculate 常数项
        int[] left = caculateNumber(eqs[0], x);
        int[] right = caculateNumber(eqs[1], x);

        int xNum = left[0] - right[0];
        int num = right[1] - left[1];
        double re = (double)num/xNum;

        System.out.printf("%c=%.3f\n", x, re);*/

//        testLocalVariable();

        System.out.println(getRemainder(-1, 5));
        System.out.println(getRemainder(1, 5));
        System.out.println(getRemainder(-111, 5));

    }
//    public static int gcd1(int a, int b){
//        return b==0 ? a : gcd1(b , a%b);
//    }

/*    // 对负数取余数
    public static int getRemainderOfNegative(int a, int b){
        int re = a % b;
        return re < 0 ? re + b : re;
    }*/
    // 取余数 兼容正负
    public static int getRemainder(int a, int b){
        int multiple = a / b;
        return a - multiple * b + (a < 0 ? b : 0);
    }

    // 测试局部变量初始化
    public static void testLocalVariable(){
        int a = 0;
        int b;
        System.out.println(a);

//        System.out.println(b); // erro java: 可能尚未初始化变量b
    }

    public static int[] caculateNumber(String eq, char x){
        int num = 0;
        int xNum = 0;

        char nowSign = '+';

        // get number
        StringBuilder numStr = new StringBuilder();
        for(int i=0; i<eq.length(); i++){
            char c = eq.charAt(i);
            if(Character.isDigit(c) || c=='-') numStr.append(c);
            else if(c == x){
                // x
                int tmp;
                if(numStr.length() == 0) tmp = nowSign=='+' ? 1:-1;
                else{
                    tmp = Integer.parseInt(numStr.toString());
                    tmp = nowSign=='+'? tmp:-tmp;
                }
                xNum += tmp;
                numStr.setLength(0);
                nowSign = '+';
            }else{
                if(numStr.length() > 0){
                    int tmp = Integer.parseInt(numStr.toString());
                    tmp = nowSign=='+'? tmp : -tmp;
                    num += tmp;
                    numStr.setLength(0);
                }
                nowSign = c;
            }
        }
        if(numStr.length() > 0){
            int tmp = Integer.parseInt(numStr.toString());
            tmp = nowSign=='+'? tmp : -tmp;
            num += tmp;
        }
        return new int[]{xNum, num};
    }

    // 辗转相除法求两数最大公约数
    public static int gcd(int a, int b){
        if(b==0) return a;
        return gcd(b, a%b);
    }

    // 计算组合数
/*    public static int caculate(int n,int k){
        if(n<=0) return 1;
        if(k>=n) return 1;
        // int sum = 0;
        int fenzi = 1;
        int fenmu = 1;
        for(int i=0; i<k; i++){
            fenzi *= (i+1);
            fenmu *= (n-i);
        }
        return fenmu/fenzi;

    }*/
}